﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using TfsBranchLib2.Model;
using TfsComLib.ItemBrowser;
using TfsComLib.TfsBranchLib2;

namespace TfsBranchLib2.View
{
    /// <summary>
    ///     Interaction logic for SourceControlPathsBox.xaml
    /// </summary>
    public partial class SourceControlPathsBox : UserControl
    {
        private BranchedHistoryContext branchedHistoryContext;

        public SourceControlPathsBox()
        {
            InitializeComponent();
        }

        internal void SetBindings(BranchedHistoryContext branchedHistoryContext)
        {
            this.branchedHistoryContext = branchedHistoryContext;
            sourceControlFilterBox.SetBinding(branchedHistoryContext.SourceControlFilter);
            serverPath.SetBinding(VcItemBox.ProjectCollectionProperty,
                new Binding
                {
                    Mode = BindingMode.OneWay,
                    Path = new PropertyPath("TfsConnection.Collection"),
                    Source = branchedHistoryContext.sourceControlBasePath
                });
            serverPath.SetBinding(VcItemBox.VcItemPathProperty,
                new Binding("SinglePath") {Mode = BindingMode.TwoWay, Source = branchedHistoryContext});
            subPath.DataContext = branchedHistoryContext;
            subPath.SetBinding(TextBox.TextProperty, new Binding("PathWithinBranches"));
        }

        private void UpdateQueryTypeBySelection(object sender, SelectionChangedEventArgs e)
        {
            if (branchedHistoryContext != null)
            {
                if (tabControl.SelectedItem == filterTab)
                {
                    branchedHistoryContext.QueryType = BranchedHistoryQueryType.BranchFilter;
                }
                else
                {
                    branchedHistoryContext.QueryType = BranchedHistoryQueryType.SingleSubPath;
                }
            }
        }
    }
}